<template>
  <div>
    <!-- 顶部组件 -->
    <header-nav></header-nav>
    <!-- 轮播图   推荐首页 -->
    <div class="banner">
      <div class="imgs">
        <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
          <van-swipe-item v-for="item in imgs" :key="item.targetId" @click="setId(item.targetId,item.typeTitle)">
            <img :src="item.pic" />
          </van-swipe-item>
        </van-swipe>
      </div>
    </div>

    <!-- 推荐歌单 -->
    <div class="remLists">
      <h4 class="title">推荐歌单</h4>
      <div class="content">
        <ul>
          <li v-for="item in Personalizedr" :key="item.id">
            <router-link tag="div" :to="'/rank/ranklist?id=' + item.id">
              <!--携带歌单id跳转播放页-->
              <div class="img">
                <img :src="item.picUrl" />
              </div>
              <p>{{ item.name }}</p>
              <span
                ><i class="iconfont icon-erji"></i
                >{{ item.playCount | playCountData }}</span
              >
            </router-link>
          </li>
        </ul>
      </div>
    </div>

    <div class="recommend-mv-box">
      <h4>推荐MV</h4>
      <!-- Swiper -->
      <div class="swiper-container swiper-container-01">
        <div class="swiper-wrapper">
          <div class="swiper-slide item" v-for="ele in MV" 
          :key="ele.id"
           @click="tomvplayer(ele.id)"
          >
          
            <div class="recommend-mv-img">
              <img :src="ele.picUrl" alt="" />
            </div>
            <p>{{ ele.name }}</p>
            <p class="artistName">{{ele.artistName}}</p>
            <span>
              <i class="iconfont icon-bofang"></i>
              {{ ele.playCount | playCountData }}
            </span>

          </div>
        </div>
        <div class="swiper-pagination swiper-pagination-01"></div>
      </div>
    </div>
  </div>
</template>

<script>
import {getBanner, getPersonalizedr, getRecommendMV} from "../api/recommend";
import headerNav from "../components/base/headerNav.vue";
import { Toast } from 'vant';
// https://3.swiper.com.cn/demo/index.html
import Swiper from "swiper";

export default {
  data() {
    return {
      imgs: null,
      Personalizedr: null,
      MV: null,
    };
  },
  methods: {
    getBannerFun() {
      getBanner().then((data) => {
        this.imgs = data.banners;
      });
    },
    getPersonalizedrFun() {
      getPersonalizedr().then((data) => {
        this.Personalizedr = data.result;
      });
    },
     tomvplayer(id) {
    this.$emit("getMvPlayerId",id)
     document.querySelector('.mvplayer').webkitRequestFullscreen() //触发div全屏
    },
    setId(id,type){
      if(type=="新歌首发"){ this.$emit("get-player-id",id);}else if(type=="视频"){
          this.$emit("getMvPlayerId",id)
     document.querySelector('.mvplayer').webkitRequestFullscreen() //触发div全屏
      }else{
        Toast('暂无碟片播放功能');
      }
    }
  },
  created() {
    this.getBannerFun(); //获取轮播图
    this.getPersonalizedrFun(); //获取推荐歌单
    getRecommendMV().then((data) => {
      //获取推荐MV
      this.MV = data.result;
    });
  },
  components: {
    headerNav,
  },
  // 过滤器
  filters: {
    playCountData(value) {
      let w = value > 10000 ? value / 10000 : value; // 万计算
      let y = w > 10000 ? parseInt(value / 10000) + "亿" : parseInt(w) + "万"; //亿计算
      return y;
    },
  },
  mounted() {
    new Swiper(".swiper-container-01", {
      // pagination: '.swiper-pagination-01',
      slidesPerView: 3, //显示个数
      paginationClickable: true,
      observer: true,
      observeParents: true,
      spaceBetween: 10, //div之间间距
    });
  },
};
</script>

<style lang="less" scoped>
.banner {
  &::before {
    content: "";
    display: block;
    height: 124px;
    background-color: #d44439;
    position: absolute;
    width: 100%;
    z-index: 0;
  }
  position: relative;
  .imgs {
    position: relative;
    left: 0px;
    right: 0px;
    top: 0px;
    margin: auto;
    width: 96%;
    border-radius: 4px;
    overflow: hidden;
    img {
      width: 100%;
    }
  }
}

.remLists {
  .title {
    height: 60px;
    line-height: 60px;
    text-indent: 5px;
    font-size: 16px;
    color: #000;
    font-weight: bold;
  }
  .content {
    ul {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-around;
      li {
        flex: 0 0 32%;
        position: relative;
        span {
          position: absolute;
          top: 0px;
          right: 0px;
          color: #fff;
          font-size: 10px;
          i {
            font-size: 15px;
            vertical-align: middle;
          }
        }
        .img {
          background-color: aqua;
          min-height: 50px;
          width: 100%;
          border-radius: 3px;
          img {
            width: 100%;
            border-radius: 3px;
          }
        }
        p {
          font-size: 12px;
          color: #565658;
          line-height: 15px;
          padding: 5px;
          margin-bottom: 10px;
          height: 26px;
          overflow: hidden;
        }
      }
    }
  }
}
.recommend-mv-box {
  height: 206px;
  h4 {
    height: 60px;
    line-height: 60px;
    text-indent: 5px;
    font-size: 16px;
    color: #000;
    font-weight: bold;
  }
  .swiper-slide {
    width: 106px !important;
    height: 150px;
    .recommend-mv-img {
      width: 106px;
      height: 106px;
      border-radius: 9px;
      overflow: hidden;
      position: relative;
      img {
        width: 100%;
        height: 100%;
      }
    }
    p {
      font-size: 12px;
      color: #565658;
      line-height: 15px;
      padding: 5px;
      height: 26px;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
    .artistName{
      position: absolute;
      left: 50%;
      transform: translateX(-50%);
      bottom:34px;
      white-space:nowrap;
      overflow: hidden;
      text-overflow:ellipsis;
      color: #fff;
    }
    span {
    position: absolute;
    top: 4px;
    right: 6px;
    color: #fff;
    font-size: 10px;

    }
  }
}
</style>